package com.tianji.promotion.handler;

import com.tianji.promotion.service.ICouponService;
import com.tianji.promotion.service.IUserCouponService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class CouponAndCodeStatusHandler {

    private final ICouponService couponService;
    private final IUserCouponService userCouponService;

    /**
     * 定时扫秒将未开始状态以及开始时间已到或已过的优惠券状态设置成发放中 同时发送其对应的code
     */
    @XxlJob("taskIssuesCouponAndCode")
    public void taskIssuesCouponAndCode(){
        couponService.taskIssuesCouponAndCode();
    }

    /**
     * 定时将发送时间已过的优惠券状态设为已结束 包括对应兑换码
     */
    @XxlJob("taskStopIssuesCouponAndCode")
    public void taskStopIssuesCouponAndCode(){
        couponService.taskStopIssuesCouponAndCode();
    }

    /**
     * 在优惠券即将过期前以短信方式提醒用户。每3天执行一次 在早上9点
     */
    @XxlJob("taskTextingMessageByRabbitMq")
    public void taskTextingMessageByRabbitMq(){
        userCouponService.taskTextingMessageByRabbitMq();
    }
}
